// pages/pay/paySuccess/paySuccess.js
const app = getApp()
const WXAPI = require("../../../api/api")
Page({

  /**
   * 页面的初始数据
   */
  data: {
    nvabarData: {
      showCapsule: 1, // 是否显示左上角图标   1表示显示    0表示不显示
      title: '支付成功', // 导航栏 中间的标题
      textColor: '#333', // 标题颜色
      bgColor: '#FAFAFA', // 导航栏背景颜色
      backUrl: '/pages/userMarket/userMarket'
    },
    orderId: '',
    orderData: {},
    imgHttp: app.globalData.imgHttp,//图片前缀
    isMaidian: '',
    anonymity: '',//1 匿名支付用户 2 非匿名支付用户
    isFocus: false,//是否关注公众号
    deleteToken: '',//true需要清空token，false不需要
    focusShow: false,
    subscribeShow: false, //订阅消息弹窗
    tmplIds: [], //订阅消息数组
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    // var orderId = '1473561774996447234'
    var orderId = options.orderId
    var anonymity = options.anonymity
    var deleteToken = options.deleteToken
    var isMaidian = ''
    console.log('anonymity',anonymity)
    this.setData({
      orderId: orderId,
      isMaidian: isMaidian,
      anonymity: anonymity,
      deleteToken: deleteToken,
    })
    this.getorderStatus()
    this.getfocus()
    this.dialog = this.selectComponent("#auth_dialog"); 
    
  },
  jumpAsset(){
    wx.switchTab({
      // url: '/pages/assets/assets',
      url:'/pages/userMarket/userMarket'
    })
  },
  // 查询订阅模版id
  getSubscriptionLs(cardType) {
    var data = {
      paySource: app.globalData.paySource,
      cardType: cardType
    }
    WXAPI.subscriptionLs(data, (res) => {
      if (res.code == 200) {
        this.setData({
          tmplIds: res.result
        })
      }
    })
  },
  getorderStatus(){
    const that = this
    var data = {
      orderId: this.data.orderId,
    }
    WXAPI.payResult(data, (res) =>{
      const data = res.result
      console.log("获取支付结果",res)
      if(res.code == 200){
        this.data.orderData = res.result
        this.setData({
          orderData: res.result,
        })
        this.getSubscriptionLs(res.result.cardType)
        if (this.data.orderData.cardMoney!=0&&this.data.orderData.cardMoney!='') {
          this.setData({
            subscribeShow: true
          })
        }else{
          this.setData({
            subscribeShow: false
          })
        }
        console.log('是否清空token',this.data.anonymity,"==============",this.data.deleteToken)
        if(this.data.anonymity == 1 || this.data.deleteToken == 'true'){//匿名支付用户,支付完成清空token
          wx.clearStorageSync()
          console.log('清空token',)
        }
      }
    })
  },
  //查询是否关注公众号
  getfocus(){
    const that = this
    WXAPI.getisCustomerAttentionMp('', (res) =>{
      const data = res.result
      console.log("查询是否关注公众号",res)
      if(res.code == 200){
        this.data.focusShow = res.result
      }
    })
  },
  handleAsster(){
    wx.switchTab({
      // url: '/pages/assets/assets',
      url:'/pages/userMarket/userMarket'
    })
  },
  handleToken(){
    var token = wx.getStorageSync('token')
    this.dialog.showPhone()
  },
  refreshintegral(){
    this.setData({
      isMaidian: false
    })
    this.getVou()
  },
  watchCard(){ //产看剩余余额
    wx.navigateTo({
      url: '/ecCanvas/pages/myShareholderCard/otherCarddetail/otherCarddetail?assetId=' + this.data.orderData.assetId + '&id=' + this.data.orderData.customerCardId,
    })
  },
  //订单详情
  handleOrder(e){  
    wx.navigateTo({
      url: '/userPageC/pages/userPersonal/order/orderDetail/orderDetail?orderId=' + this.data.orderData.orderManageId,
    })
  },
  //查看我的卡包
  handleassets(){
    wx.switchTab({
      url: '/pages/userMarket/userMarket',
    })
  },
  getVou(){
    var data = {
      orderId: this.data.orderId
    }
    WXAPI.receiveAnonymousOrder(data,(res) => {
      if(res.codd == 200){
        wx.switchTab({
          url: '/pages/assets/assets',
        })
      }
    })
  },
  copy(){ //复制
    wx.setClipboardData({
      data: this.data.orderData.orderId,
      success (res) {
        wx.showToast({
          title: '复制成功',
        })
      }
    })    
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  // onShareAppMessage: function () {

  // }
})